/*
 * user.h
 *
 *  Created on: 24-Dec-2010
 *      Author: sudhix


#ifndef USER_H_
#define USER_H_


#include <iostream>
#include <string>
#include <pthread.h>
#include <gloox/client.h>
#include <gloox/messagehandler.h>
#include <gloox/connectionlistener.h>
#include <gloox/presencehandler.h>
#include <gloox/connectiontcpclient.h>
#include <gloox/messagesession.h>
#include <gloox/message.h>
#include <gloox/messageeventfilter.h>
#include <gloox/messageeventhandler.h>
#include <gloox/chatstatefilter.h>
#include <gloox/chatstatehandler.h>
#include <gloox/messagesessionhandler.h>
#include <gloox/subscriptionhandler.h>
#include <gloox/privatexmlhandler.h>
#include <gloox/rostermanager.h>
#include <qobject.h>


//#include "../headers/user.h"

using namespace std;
using namespace gloox;

void* SendMessage(void*);

void *RecvMsg1(void*);

class UserClientCredentials
{
private:
        string	iUserName;
        string 	iPassword;
        string 	iHost;
public:
        UserClientCredentials()
        {

        }
        UserClientCredentials(string aUserName, string aPassword, string aHost) : iUserName(aUserName), iPassword(aPassword), iHost(aHost){ }
    string getHost() const
    {
        return iHost;
    }
    string getPassword() const
    {
        return iPassword;
    }
    string getUserName() const
    {
        return iUserName;
    }
    void setHost(string aHost)
    {
        iHost = aHost;
    }
    void setPassword(string aPassword)
    {
        iPassword = aPassword;
    }
    void setUserName(string aUserName)
    {
        iUserName = aUserName;
    }
};


class UserClient : public MessageHandler, MessageSessionHandler, ConnectionListener, MessageEventHandler, ChatStateHandler
{
public:
        ConnectionError er;
        bool 	iConnected;
        Ui::MainWindow *parent;
public:
        //ctor and dtor
        UserClient();
        ~UserClient();

        //user details
        void SetUserDetails(UserClientCredentials aUserCredentials);
        void SetDestinationUser(UserClientCredentials aUserCredentials);
        bool RegisterUser(UserClientCredentials aUserCredentials);
        void SendMessageclass( string ip);
        //connection related
        bool ConnecttosServer();
        bool CompleteConnection();

        //virtual functions
        virtual void handlePresence( const Presence& presence );
        virtual void onConnect();
        virtual bool onTLSConnect(const CertInfo& info);
        virtual void onDisconnect(ConnectionError e );
        virtual void handleMessage( const Message& msg, MessageSession* session = 0 );
        virtual void handleMessageEvent( const JID& from, MessageEventType event );
        virtual void handleMessageSession( MessageSession* session );
        virtual void handleChatState( const JID& from, ChatStateType state );

        //return client JID
        JID	GetJid()
        {
                return iUserJid;
        }

public:
        Client					*j;
        string 					iUserJidString, iDestJidString;
        JID					iUserJid, iDestJid;
        UserClientCredentials                   iUser, iDestUser;

        //MessageEventFilter	*iMessageEventFilter;
        MessageSession			*iMessageSession;
        ChatStateFilter			*iChatStateFilter;
};

class RoosterManagement : public IqHandler,  PresenceHandler,  SubscriptionHandler, PrivateXMLHandler
{
public:
        //ctor and dtor
        RoosterManagement(ClientBase * aBase);
        ~RoosterManagement();

        //functions
        void PopulateAtServer();
        void Sync();
        Roster* roster();
    void Subscribe( const JID& aJid, string& aNname, StringList& aGroups, string& aMsg);
    void Remove( const JID& aJid );
    void RegisterRosterListener( RosterListener* aRoster, bool aSync = true );

private:
        RosterListener		*iRosterListener;
        Roster 				iRoster;
    ClientBase			*iParent;
    RosterItem			*iRosterItem;
    PrivateXML			*iPrivateXML;

};

inline void DisplayMessage(string str)
{
        cout << endl <<str <<endl;
}

#endif  USER_H_ */
